package cn.tedu.weibo.service.impl;

import cn.tedu.weibo.exception.ServiceException;
import cn.tedu.weibo.mapper.WeiboMapper;
import cn.tedu.weibo.pojo.dto.WeiboDTO;
import cn.tedu.weibo.pojo.entity.Weibo;
import cn.tedu.weibo.pojo.vo.WeiboDetailVO;
import cn.tedu.weibo.pojo.vo.WeiboIndexVO;
import cn.tedu.weibo.response.StatusCode;
import cn.tedu.weibo.service.WeiboService;
import lombok.Setter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WeiboServicelmpl implements WeiboService {

    @Autowired
    WeiboMapper mapper;

    @Override
    public void addNew(WeiboDTO weiboDTO) {
        Weibo weibo = new Weibo();
        BeanUtils.copyProperties(weiboDTO, weibo);
        weibo.setCreated(new Date());
        mapper.insert(weibo);
    }

    @Override
    public List<WeiboIndexVO> listForIndex() {
        return mapper.selectForIndex();
    }

    @Override
    public List<WeiboIndexVO> listForIndexByUserId(Long userId) {
        return mapper.selectForIndexByUserId(userId);
    }

    @Override
    public void deleteById(Long id) {
         mapper.deleteById(id);
    }

    @Override
    public WeiboDetailVO datailById(Long id) {
        return mapper.datailById(id);
    }
}
